package contato.DAO;

import java.util.ArrayList;
import java.util.Date;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import rta.dataacess.Cercanot;
import rta.dataacess.Confignot;
import rta.dataacess.Imei;
import rta.dataacess.Notifica;
import rta.dataacess.Usuario;

public class NotificacercaDao extends GenericDAO<Cercanot> {

	public NotificacercaDao() {
		super(Cercanot.class);

	}

	public NotificacercaDao(EntityManager entityManager) {
		super(Cercanot.class, entityManager);
	}


	public ArrayList<Cercanot> findbyImeicerca(Date datacerca1,
			Date datacerca2, String rast) {
		
		ArrayList<Cercanot> noti = null;
		String hql = "FROM Cercanot WHERE data >= ? AND data <= ? AND imei = ? order by data";

		EntityManager entityManager = getEntityManager();
		Query query = entityManager.createQuery(hql);
		query.setParameter(1, datacerca1);
		query.setParameter(2, datacerca2);
		query.setParameter(3, rast);

		try {
			noti = (ArrayList<Cercanot>) query.getResultList();

			return noti;

		} catch (RuntimeException e) {

			return noti = null;

		}
		
	}

	public ArrayList<Cercanot> findbyImeicercaRast(String rast) {

		ArrayList<Cercanot> noti = null;
		String hql = "FROM Cercanot WHERE imei = ? ";

		EntityManager entityManager = getEntityManager();
		Query query = entityManager.createQuery(hql);
		query.setParameter(1, rast);

		try {
			noti = (ArrayList<Cercanot>) query.getResultList();

			return noti;

		} catch (RuntimeException e) {

			return noti = null;

		}
	}

}
